home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 7 / Amiga Format AFCD07 (Dec 1996, Issue 91).iso / serious / shareware / programming / ixemul-complete / man / cat7 / re_format.0
Text File  |  1996-09-01  |  12KB  |  265 lines

  1.  
  2.  
  3.  
  4. RE_FORMAT(7)                                         RE_FORMAT(7)
  5.  
  6.  
  7. NNAAMMEE
  8.        re_format - POSIX 1003.2 regular expressions
  9.  
  10. DDEESSCCRRIIPPTTIIOONN
  11.        Regular expressions (``RE''s), as defined in POSIX 1003.2,
  12.        come in two forms: modern REs  (roughly  those  of  _e_g_r_e_p;
  13.        1003.2  calls  these  ``extended''  REs)  and obsolete REs
  14.        (roughly those of _e_d; 1003.2 ``basic'' REs).  Obsolete REs
  15.        mostly  exist  for backward compatibility in some old pro-
  16.        grams; they will be discussed at the end.   1003.2  leaves
  17.        some  aspects  of  RE  syntax and semantics open; `' marks
  18.        decisions on these aspects that may not be fully  portable
  19.        to other 1003.2 implementations.
  20.  
  21.        A (modern) RE is one or more non-empty _b_r_a_n_c_h_e_s, separated
  22.        by `|'.  It matches  anything  that  matches  one  of  the
  23.        branches.
  24.  
  25.        A  branch is one or more _p_i_e_c_e_s, concatenated.  It matches
  26.        a match for the first, followed by a match for the second,
  27.        etc.
  28.  
  29.        A piece is an _a_t_o_m possibly followed by a single `*', `+',
  30.        `?', or _b_o_u_n_d.  An atom followed by `*' matches a sequence
  31.        of 0 or more matches of the atom.  An atom followed by `+'
  32.        matches a sequence of 1 or more matches of the  atom.   An
  33.        atom  followed by `?' matches a sequence of 0 or 1 matches
  34.        of the atom.
  35.  
  36.        A _b_o_u_n_d is `{' followed by an  unsigned  decimal  integer,
  37.        possibly  followed  by  `,'  possibly  followed by another
  38.        unsigned decimal integer, always  followed  by  `}'.   The
  39.        integers  must  lie  between 0 and RE_DUP_MAX (255) inclu-
  40.        sive, and if there are two of  them,  the  first  may  not
  41.        exceed the second.  An atom followed by a bound containing
  42.        one integer _i and no comma matches a sequence of exactly _i
  43.        matches of the atom.  An atom followed by a bound contain-
  44.        ing one integer _i and a comma matches a sequence of  _i  or
  45.        more  matches  of  the  atom.  An atom followed by a bound
  46.        containing two integers _i and _j matches a  sequence  of  _i
  47.        through _j (inclusive) matches of the atom.
  48.  
  49.        An atom is a regular expression enclosed in `()' (matching
  50.        a match for the regular expression), an empty set of  `()'
  51.        (matching  the  null  string),  a  _b_r_a_c_k_e_t _e_x_p_r_e_s_s_i_o_n (see
  52.        below), `.'  (matching any single character), `^'  (match-
  53.        ing  the  null  string  at  the  beginning of a line), `$'
  54.        (matching the null string at the end of  a  line),  a  `\'
  55.        followed by one of the characters `^.[$()|*+?{\' (matching
  56.        that character taken as an ordinary character), a `\' fol-
  57.        lowed  by  any  other  character  (matching that character
  58.        taken as an ordinary character, as if the `\' had not been
  59.        present), or a single character with no other significance
  60.        (matching that character).  A `{' followed by a  character
  61.  
  62.  
  63.  
  64.                           March 20, 1994                        1
  65.  
  66.  
  67.  
  68.  
  69.  
  70. RE_FORMAT(7)                                         RE_FORMAT(7)
  71.  
  72.  
  73.        other  than  a  digit  is  an  ordinary character, not the
  74.        beginning of a bound.  It is illegal to  end  an  RE  with
  75.        `\'.
  76.  
  77.        A  _b_r_a_c_k_e_t  _e_x_p_r_e_s_s_i_o_n is a list of characters enclosed in
  78.        `[]'.  It normally matches any single character  from  the
  79.        list  (but  see  below).   If the list begins with `^', it
  80.        matches any single character (but see below) _n_o_t from  the
  81.        rest of the list.  If two characters in the list are sepa-
  82.        rated by `-', this is shorthand  for  the  full  _r_a_n_g_e  of
  83.        characters  between those two (inclusive) in the collating
  84.        sequence, e.g. `[0-9]' in ASCII matches any decimal digit.
  85.        It  is  illegal  for two ranges to share an endpoint, e.g.
  86.        `a-c-e'.  Ranges  are  very  collating-sequence-dependent,
  87.        and portable programs should avoid relying on them.
  88.  
  89.        To  include  a  literal `]' in the list, make it the first
  90.        character (following a possible `^').  To include  a  lit-
  91.        eral `-', make it the first or last character, or the sec-
  92.        ond endpoint of a range.  To use  a  literal  `-'  as  the
  93.        first  endpoint of a range, enclose it in `[.' and `.]' to
  94.        make it a collating element (see below).  With the  excep-
  95.        tion  of  these  and some combinations using `[' (see next
  96.        paragraphs), all other special characters, including  `\',
  97.        lose  their  special significance within a bracket expres-
  98.        sion.
  99.  
  100.        Within a bracket expression, a collating element (a  char-
  101.        acter,  a  multi-character sequence that collates as if it
  102.        were a single character, or a collating-sequence name  for
  103.        either)  enclosed in `[.' and `.]' stands for the sequence
  104.        of characters of that collating element.  The sequence  is
  105.        a  single  element  of  the  bracket expression's list.  A
  106.        bracket expression containing a multi-character  collating
  107.        element  can  thus  match more than one character, e.g. if
  108.        the collating sequence includes a `ch' collating  element,
  109.        then the RE `[[.ch.]]*c' matches the first five characters
  110.        of `chchcc'.
  111.  
  112.        Within a bracket expression, a collating element  enclosed
  113.        in `[=' and `=]' is an equivalence class, standing for the
  114.        sequences of characters of all collating elements  equiva-
  115.        lent  to  that  one,  including  itself.  (If there are no
  116.        other equivalent collating elements, the treatment  is  as
  117.        if  the  enclosing  delimiters  were  `[.' and `.]'.)  For
  118.        example, if o and o^ are  the  members  of  an  equivalence
  119.        class,  then `[[=o=]]', `[[=o^=]]', and `[oo^]' are all syn-
  120.        onymous.  An equivalence class may not be an endpoint of a
  121.        range.
  122.  
  123.        Within a bracket expression, the name of a _c_h_a_r_a_c_t_e_r _c_l_a_s_s
  124.        enclosed in `[:' and `:]' stands for the list of all char-
  125.        acters  belonging to that class.  Standard character class
  126.        names are:
  127.  
  128.  
  129.  
  130.                           March 20, 1994                        2
  131.  
  132.  
  133.  
  134.  
  135.  
  136. RE_FORMAT(7)                                         RE_FORMAT(7)
  137.  
  138.  
  139.               alnum       digit       punct
  140.               alpha       graph       space
  141.               blank       lower       upper
  142.               cntrl       print       xdigit
  143.  
  144.        These stand for the character classes defined in _c_t_y_p_e(3).
  145.        A locale may provide others.  A character class may not be
  146.        used as an endpoint of a range.
  147.  
  148.        There are two special cases of  bracket  expressions:  the
  149.        bracket expressions `[[:<:]]' and `[[:>:]]' match the null
  150.        string at the beginning and end of a word respectively.  A
  151.        word  is defined as a sequence of word characters which is
  152.        neither preceded nor followed by word characters.  A  word
  153.        character  is  an _a_l_n_u_m character (as defined by _c_t_y_p_e(3))
  154.        or an underscore.  This is an extension,  compatible  with
  155.        but not specified by POSIX 1003.2, and should be used with
  156.        caution in software intended to be portable to other  sys-
  157.        tems.
  158.  
  159.        In  the  event  that  an RE could match more than one sub-
  160.        string of a given string, the RE matches the one  starting
  161.        earliest  in  the string.  If the RE could match more than
  162.        one substring starting  at  that  point,  it  matches  the
  163.        longest.   Subexpressions  also match the longest possible
  164.        substrings, subject to the constraint that the whole match
  165.        be  as long as possible, with subexpressions starting ear-
  166.        lier in the RE taking priority over ones  starting  later.
  167.        Note  that  higher-level subexpressions thus take priority
  168.        over their lower-level component subexpressions.
  169.  
  170.        Match lengths are measured in  characters,  not  collating
  171.        elements.   A  null  string  is  considered longer than no
  172.        match at all.  For example, `bb*' matches the three middle
  173.        characters    of   `abbbc',   `(wee|week)(knights|nights)'
  174.        matches all ten characters of `weeknights', when  `(.*).*'
  175.        is  matched  against `abc' the parenthesized subexpression
  176.        matches all three characters, and when `(a*)*' is  matched
  177.        against  `bc'  both  the  whole  RE  and the parenthesized
  178.        subexpression match the null string.
  179.  
  180.        If case-independent matching is specified, the  effect  is
  181.        much  as  if  all  case distinctions had vanished from the
  182.        alphabet.  When an  alphabetic  that  exists  in  multiple
  183.        cases  appears  as an ordinary character outside a bracket
  184.        expression, it is effectively transformed into  a  bracket
  185.        expression containing both cases, e.g. `x' becomes `[xX]'.
  186.        When it appears inside  a  bracket  expression,  all  case
  187.        counterparts of it are added to the bracket expression, so
  188.        that  (e.g.)  `[x]'  becomes  `[xX]'  and  `[^x]'  becomes
  189.        `[^xX]'.
  190.  
  191.        No particular limit is imposed on the length of REs.  Pro-
  192.        grams intended to be portable should not employ REs longer
  193.  
  194.  
  195.  
  196.                           March 20, 1994                        3
  197.  
  198.  
  199.  
  200.  
  201.  
  202. RE_FORMAT(7)                                         RE_FORMAT(7)
  203.  
  204.  
  205.        than  256 bytes, as an implementation can refuse to accept
  206.        such REs and remain POSIX-compliant.
  207.  
  208.        Obsolete (``basic'') regular expressions differ in several
  209.        respects.   `|',  `+', and `?' are ordinary characters and
  210.        there is  no  equivalent  for  their  functionality.   The
  211.        delimiters  for bounds are `\{' and `\}', with `{' and `}'
  212.        by themselves ordinary characters.   The  parentheses  for
  213.        nested  subexpressions are `\(' and `\)', with `(' and `)'
  214.        by themselves ordinary characters.   `^'  is  an  ordinary
  215.        character  except at the beginning of the RE or the begin-
  216.        ning of a parenthesized subexpression, `$' is an  ordinary
  217.        character  except  at  the  end  of the RE or the end of a
  218.        parenthesized subexpression, and `*' is an ordinary  char-
  219.        acter  if  it  appears  at  the beginning of the RE or the
  220.        beginning of a parenthesized subexpression (after a possi-
  221.        ble leading `^').  Finally, there is one new type of atom,
  222.        a _b_a_c_k _r_e_f_e_r_e_n_c_e: `\' followed by a non-zero decimal digit
  223.        _d  matches  the same sequence of characters matched by the
  224.        _dth parenthesized subexpression (numbering  subexpressions
  225.        by  the  positions  of  their opening parentheses, left to
  226.        right), so that (e.g.) `\([bc]\)\1' matches `bb'  or  `cc'
  227.        but not `bc'.
  228.  
  229. SSEEEE AALLSSOO
  230.        regex(3)
  231.  
  232.        POSIX 1003.2, section 2.8 (Regular Expression Notation).
  233.  
  234. BBUUGGSS
  235.        Having two kinds of REs is a botch.
  236.  
  237.        The current 1003.2 spec says that `)' is an ordinary char-
  238.        acter in the absence of an  unmatched  `(';  this  was  an
  239.        unintentional  result  of  a  wording error, and change is
  240.        likely.  Avoid relying on it.
  241.  
  242.        Back references are a dreadful botch, posing  major  prob-
  243.        lems  for  efficient implementations.  They are also some-
  244.        what  vaguely  defined   (does   `a\(\(b\)*\2\)*d'   match
  245.        `abbbd'?).  Avoid using them.
  246.  
  247.        1003.2's  specification  of  case-independent  matching is
  248.        vague.  The ``one  case  implies  all  cases''  definition
  249.        given  above is current consensus among implementors as to
  250.        the right interpretation.
  251.  
  252.        The syntax for word boundaries is incredibly ugly.
  253.  
  254.  
  255.  
  256.  
  257.  
  258.  
  259.  
  260.  
  261.  
  262.                           March 20, 1994                        4
  263.  
  264.  
  265.